package com.ibk.system.map;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.ibk.system.R;

public class GoogleMapServiceTest extends MapActivity {
	LocationListener mLocationListener;
	MapView mapView;
	MapController mc;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mapview);
		mapView = (MapView) findViewById(R.id.mapview);
		mapView.setBuiltInZoomControls(true);
		mapView.setSatellite(true);
		LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
		mc = mapView.getController();
		mLocationListener = new LocationListener() {
			public void onLocationChanged(Location location) {
				if (location != null) {
					Toast.makeText(
							getBaseContext(),
							"latitude " + location.getLatitude() + ", " + "longitude"
									+ location.getLongitude(),
							Toast.LENGTH_LONG).show();
					GeoPoint gb = new GeoPoint(
							(int) location.getLatitude() * 1000000,
							(int) location.getLongitude() * 1000000);
					mc.animateTo(gb);
					mc.setZoom(14);
				}
			}

			public void onProviderDisabled(String arg0) {
				/*
				 * Toast.makeText(getBaseContext() ,"provider disable"+arg0,
				 * Toast.LENGTH_SHORT).show();
				 */
			}

			public void onProviderEnabled(String arg0) {
				/*
				 * Toast.makeText(getBaseContext() ,"provider enabled"+arg0,
				 * Toast.LENGTH_SHORT).show();
				 */
			}

			public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
				Toast.makeText(getBaseContext(),
						"GPS changed.\n" + arg0 + ", " + arg1 + "",
						Toast.LENGTH_SHORT).show();
			}
		};
		// milisecond, meter, listener
		lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 1,
				mLocationListener);
	}

	protected void onDestroy() {
		super.onDestroy();
		LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
		lm.removeUpdates(mLocationListener);
	}

	@Override
	protected boolean isRouteDisplayed() {
		return false;
	}

}
